home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / UNITS / ANIMICON.CPP < prev    next >
C/C++ Source or Header  |  1993-02-27  |  5KB  |  193 lines

  1. #ifndef ANIMICON.H
  2. #include "animicon.h"
  3. #endif
  4.  
  5. #include <string.h>
  6.  
  7. animicon::animicon(char * filename, icon::flagType flags, yakLib * myYakLib)
  8. {
  9.   firstFrame = lastFrame = thisFrame = NULL;
  10.   numberOfFrames=0;
  11.   addAll(filename, flags, myYakLib);
  12. }
  13.  
  14. animicon::~animicon()
  15. {
  16.   animiconNode * nodeCounter, * nextNodeCounter;
  17.   if (firstFrame != lastFrame)
  18.   {
  19.     for (nodeCounter = firstFrame; nodeCounter != lastFrame; nodeCounter = nextNodeCounter)
  20.     {
  21.       nextNodeCounter = nodeCounter->nextFrame;
  22.       delete nodeCounter;
  23.     }
  24.     delete lastFrame;
  25.   }
  26.   if ((firstFrame == lastFrame) && (firstFrame != NULL))
  27.     removeTail();
  28.   firstFrame = lastFrame = thisFrame = NULL;
  29.   numberOfFrames = 0;
  30. }
  31.  
  32.  
  33. char far * animicon::add(animiconNode * thisNode)
  34. {
  35.   numberOfFrames++;
  36.   if (firstFrame != NULL)
  37.   {
  38.     lastFrame->nextFrame = thisNode; // make the new node
  39.     lastFrame->nextFrame->prevFrame = lastFrame; //make new node point back
  40.     firstFrame->prevFrame = lastFrame;
  41.     lastFrame = lastFrame->nextFrame;
  42.   }
  43.   else
  44.   {
  45.     firstFrame = thisNode; // make the new node
  46.     lastFrame = firstFrame;
  47.     lastFrame->prevFrame = firstFrame; //make new node point back
  48.     firstFrame->prevFrame = lastFrame; //so it wraps backwards too.
  49.     thisFrame = firstFrame; // look at the first frame for anim purposes.
  50.   }
  51.   if (lastFrame->nextFrame)
  52.     add(lastFrame->nextFrame);
  53.   else
  54.     lastFrame->nextFrame = firstFrame;
  55.   return lastFrame->picture.unrolledPic;
  56. }
  57.  
  58. char far * animicon::add(char far * filename, icon::flagType flags, yakLib * myYakLib)
  59. {
  60.   numberOfFrames++;
  61.   if (firstFrame != NULL)
  62.   {
  63.     lastFrame->nextFrame = new animiconNode; // make the new node
  64.     lastFrame->nextFrame->prevFrame = lastFrame; //make new node point back
  65.     lastFrame = lastFrame->nextFrame; //make tail point to new node
  66.     lastFrame->nextFrame = firstFrame; // make last frame point to head
  67.     lastFrame->picture.load(filename, flags, myYakLib); //make last frame's icon point to the arg
  68.     firstFrame->prevFrame = lastFrame;
  69.   }
  70.   else
  71.   {
  72.     firstFrame = new animiconNode; // make the new node
  73.     lastFrame = firstFrame;
  74.     lastFrame->prevFrame = firstFrame; //make new node point back
  75.     lastFrame->nextFrame = firstFrame; // make last frame point to head
  76.     lastFrame->picture.load(filename, flags, myYakLib); //make last frame's icon point to the arg
  77.     firstFrame->prevFrame = lastFrame; //so it wraps backwards too.
  78.     thisFrame = firstFrame; // look at the first frame for anim purposes.
  79.   }
  80.   return lastFrame->picture.unrolledPic;
  81. }
  82.  
  83. void animicon::removeTail(void)
  84. {
  85.   if (firstFrame != lastFrame)
  86.   {
  87.     lastFrame = lastFrame->prevFrame;
  88.     delete (lastFrame->nextFrame);
  89.     lastFrame->nextFrame = firstFrame;
  90.     firstFrame->prevFrame = lastFrame;
  91.   }
  92.   else if (firstFrame == lastFrame)
  93.   {
  94.     delete firstFrame;
  95.     firstFrame = lastFrame = thisFrame = NULL;
  96.   }
  97.   numberOfFrames--;
  98. }
  99.  
  100.  
  101. void animicon::addAll(char far * filename, icon::flagType flags, yakLib * myYakLib)
  102. {
  103.   char dummyfile[13], counter[2];
  104.   strcpy(counter, "2");
  105.   strcpy(dummyfile, filename);
  106.   strcat(dummyfile, ".yak");
  107.   while((add(dummyfile, flags, myYakLib) != NULL))  // while there are still files to add
  108.     {
  109.     strcpy(dummyfile, filename);
  110.     if (strlen(dummyfile) < 8)
  111.     {
  112.       strcat(dummyfile, counter);
  113.     }
  114.     else
  115.       dummyfile[strlen(dummyfile) -1] = counter[0];
  116.     strcat(dummyfile, ".yak");
  117.     ++counter[0];
  118.     }
  119.   removeTail();
  120.   if (lastFrame->picture.unrolledPic == NULL)
  121.     firstFrame = NULL;
  122.  
  123. }
  124.  
  125.  
  126. void animicon::advance()
  127. {
  128.   if (thisFrame != NULL)
  129.     thisFrame = thisFrame->nextFrame;
  130. }
  131.  
  132. void animicon::show(int x, int y, word pagebase)
  133. {
  134.   thisFrame->picture.show(x, y, pagebase);
  135.   advance();
  136. }
  137.  
  138. void animicon::draw(int x, int y, word pagebase)
  139. {
  140.   thisFrame->picture.showMasked(x, y, pagebase);
  141. }
  142.  
  143. void animicon::hide(int x, int y, word toOffset, word fromOffset)
  144. {
  145.   thisFrame->prevFrame->picture.hide(x, y, toOffset, fromOffset);
  146. }
  147.  
  148. void animicon::showZoomed(int x, int y, word offset, int newWidth)
  149. {
  150.   thisFrame->picture.showZoomed(x, y, offset, newWidth);
  151.   advance();
  152. }
  153.  
  154. void animicon::drawZoomed(int x, int y, word offset, int newWidth)
  155. {
  156.   thisFrame->picture.showZoomed(x, y, offset, newWidth);
  157. }
  158.  
  159. void animslave::draw(int x, int y, word pagebase)
  160. {
  161.   thisFrame->picture.showMasked(x, y, pagebase);
  162. }
  163.  
  164. void animslave::show(int x, int y, word pagebase)
  165. {
  166.   thisFrame->picture.showMasked(x, y, pagebase);
  167.   advance();
  168. }
  169.  
  170. void animslave::showZoomed(int x, int y, word offset, int newWidth)
  171. {
  172.   thisFrame->picture.showZoomed(x, y, offset, newWidth);
  173.   advance();
  174. }
  175.  
  176. void animslave::drawZoomed(int x, int y, word offset, int newWidth)
  177. {
  178.   thisFrame->picture.showZoomed(x, y, offset, newWidth);
  179. }
  180.  
  181. void animslave::advance()
  182. {
  183.   if (thisFrame != NULL)
  184.     thisFrame = thisFrame->nextFrame;
  185. }
  186.  
  187.  
  188. void animslave::advance(int numFrames)
  189. {
  190.   for (int counter = 0; counter < numFrames; ++counter)
  191.     advance();
  192. }
  193.